package leetcode.code0997;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;
import leetcode.helper.MaxDebug;

public class Solution implements IDebug {

	public int findJudge(int n, int[][] trust) {
		int[] t = new int[n + 1];
		boolean[] t1 = new boolean[n + 1];
		for (int[] element : trust) {
			int a = element[0];
			int b = element[1];
			t[b]++;
			t1[a] = true;
		}
		for (int i = 1; i <= n; i++) {
			if (!t1[i] && t[i] == n - 1) {
				return i;
			}
		}
		return -1;
	}

	@Override
	public void debug1() {
		HelpDebug.compare(2, this.findJudge(2, HelpDebug.str2array1("[[1,2]]")));
	}

	@Override
	public void debug2() {
		HelpDebug.compare(3, this.findJudge(3, HelpDebug.str2array1("[[1,3],[2,3]]")));
	}

	@Override
	public void debug3() {
		HelpDebug.compare(-1, this.findJudge(3, HelpDebug.str2array1("[[1,3],[2,3],[3,1]]")));
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		MaxDebug.debug14(so);

	}

}
